﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MYSMRM.Dao.Base;
using MYSMRM.Dao.Interface;
using MYSMRM.Model;

namespace MYSMRM.Dao.Implement
{
    public class QSQuestionDao : DaoBase<QSQuestion>, IQSQuestionDao
    {
        public IQueryable<QSQuestion> LoadAllByPage(out long total, int id, int page, int rows, string order, string sort)
        {
            var list = this.LoadAll().Where(w => w.ID != null && w.ID == id);

            total = list.LongCount();

            //list = list.OrderByDescending(o => o.IsFirst);
            //list = list.OrderBy(sort + " " + order);

            list = list.Skip((page - 1) * rows).Take(rows);

            return list;
        }

        public IQueryable<QSQuestion> LoadAllEnable(int id)
        {
            return from li in this.LoadAll()
                   where li.ID == id
                   orderby li.ID
                   select li;
        }

        public void DeleteQuestionsByTopicID(int id)
        {
            ExecuteNonQuery(string.Format("delete from QS_QUESTION where I_TOPIC_ID={0}", id));
        }

    }
}
